<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<script language="javascript" type="text/javascript" src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
	.exportBtn{
		background:#339900;
		padding:3px 5px;
		color:#FFFFFF;
		border:0px;
		float:right;
		cursor:pointer;
		margin:3px 10px 0 0;
	}
	.order_opera{
		cursor: pointer;
	    display: block;
	    margin-top: 2px;
	    width: 100px;
		padding: 3px 10px;
		background-color:#1fd082 !important;
		color:#FFF	
	}
	.selectStatus{
		color:blue;
		cursor:pointer;
	}
</style>
</head>
<body>
	<div class="page_header">
		<div class="table_tool">
			<ul class="clearfix">
				<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
				<li class="line"></li>
				<!--<li class="btn" id="Order_confirm"><i class="icon-tags"></i> 批量确认</li>	
				<li class="line"></li>-->
				<li class="openwin btn" etitle="添加订单" eheight="500px" ewidth="1100px" ehref="{:U('Order/add')}" id="Order_add"><i class="icon-plus"></i>添加订单</li>
				<!-- <li class="btn" id="Order_deal"><i class="icon-tags"></i> 批量分配</li>	 -->
				<input type="button" class="exportBtn" id="caiwuBtn" value="导出财务报表">
				<input type="button" class="exportBtn" id="exportBtn" value="导出订单">	
			</ul>
		</div>
		
		<form name="searchForm" id="searchForm" method="post" action="{:U('Order/export')}">
			<div class="search_box">
				<select class="form_ele" name="city" id="city">
					<option value="">请选择城市</option>
					<volist name='cityarr' id='v'>
						<option value="{$key}">{$v[1]}</option>
					</volist>
				</select>
				<select class="form_ele" name="outletid" id="outletid" style="width:120px;">
					<option value="">请选择餐厅</option>
					<volist name='outlet' id='v'>
						<option value="{$v.id}">{$v.title}</option>
					</volist>
				</select>
				<select class="form_ele" name="status" id="status">
					<option value="">订单状态</option>
					<volist name="status" id="v">
						<option value="{$key}">{$v}</option>
					</volist>
				</select>
				<select class="form_ele" name="dealid" id="dealid">
					<option value="">请选择配送员</option>
					<volist name="user" id="v">
						<option value="{$v.id}">{$v.realname}</option>
					</volist>
				</select>
				<input type="text" name="startTime" id="start" class="form_ele" placeholder="请选择开始时间"
							onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{:date('Y-m-d')} 00:00:00"
							style="width:110px;">
						-
				<input type="text" name="endTime" id="end" class="form_ele" placeholder="请选择结束时间" 
					onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{:date('Y-m-d')} 23:59:59" 
					style="width:110px;">
					
				<input type="text" class="form_ele" name="keywords" id="keywords" placeholder="请输入关键字搜索">
				<span id="doRest" class="doSearch searchbtn">搜索</span>
				<span id="doRest" class="doSearch doreset">重置</span>
			</div>
		</form>
		
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
$(function(){
	
	//订单状态
	$('.selectStatus').live('click',function(){
		var id = $(this).attr('dataid');
		var href    = "{:U('Order/order_status')}&id="+id;
		var width   = '530px';
		var height  = '400px';
		var title   = '查看订单状态';
		openDialog('Order_order_status',href,width,height,title);
	});
	
	//正在确认订单
	$('.order_confirm').live('click',function(){
		var id = $(this).attr('id');
		$.get("{:U('Order/order_confirm')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});
	});
	//确认订单
	$('.order_isconfirm').live('click',function(){
		var id = $(this).attr('id');
		$.get("{:U('Order/order_isconfirm')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});
	});
	//订单已报餐
	$('.order_notify').live('click',function(){
		var id = $(this).attr('id');
		$.get("{:U('Order/order_notify')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});
	});
	//分配订单
	$('.order_fenpei').live('click',function(){
		var orderno = $(this).attr('orderno');
		var id      = $(this).attr('id');
		var href    = "{:U('Order/order_fenpei')}&id="+id+"&orderno="+orderno;
		var width   = '320px';
		var height  = '160px';
		var title   = '分配订单';
		openDialog('Order_order_fenpei',href,width,height,title);
	});
	//订单需要修改
	$('.order_neededit').live('click',function(){
		var orderno = $(this).attr('orderno');
		var id      = $(this).attr('id');
		var href    = "{:U('Order/order_neededit')}&id="+id+"&orderno="+orderno;
		var width   = '420px';
		var height  = '240px';
		var title   = '订单需要修改';
		openDialog('Order_order_neededit',href,width,height,title);
	});
	//订单已修改
	$('.order_isedit').live('click',function(){
		var id = $(this).attr('id');
		$.get("{:U('Order/order_isedit')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});
	});
	//餐厅已受理
	$('.order_editok').live('click',function(){
		var id = $(this).attr('id');
		$.get("{:U('Order/order_editok')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});
	});
	//订单投诉中
	$('.order_complaint').live('click',function(){
		
		var orderno = $(this).attr('orderno');
		var id      = $(this).attr('id');
		var href    = "{:U('Order/order_complaint')}&id="+id+"&orderno="+orderno;
		var width   = '420px';
		var height  = '240px';
		var title   = '客人投诉订单';
		openDialog('Order_order_complaint',href,width,height,title);
		
		/*var id = $(this).attr('id');
		$.get("{:U('Order/order_complaint')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});*/
	});
	//订单投诉已处理
	$('.order_iscomplaint').live('click',function(){
		
		var orderno = $(this).attr('orderno');
		var id      = $(this).attr('id');
		var href    = "{:U('Order/order_iscomplaint')}&id="+id+"&orderno="+orderno;
		var width   = '420px';
		var height  = '240px';
		var title   = '订单投诉已处理';
		openDialog('Order_order_iscomplaint',href,width,height,title);

		/*var id = $(this).attr('id');
		$.get("{:U('Order/order_iscomplaint')}",{id:id},function(data){
			if(data.status==1){
				$('.et_tfoot .page_refresh').click(); //刷新加载
				setInterval(setRed,1000);
			}else{
				windowApi.lhgdialog.tips(data.info);
			}
		});*/
	});
	//取消订单
	$('.order_cancel').live('click',function(){
		var id  = $(this).attr('id');
		var msg = "确认将该订单取消吗？";
		windowApi.lhgdialog.confirm(msg, function(){
			$.get("{:U('Order/order_cancel')}",{ id: id },function(data){
				if(data.status==1){
					windowApi.lhgdialog.tips('订单取消成功！');
					$('.et_tfoot .page_refresh').click(); //刷新加载
					setInterval(setBlue,1000);
				}else{
					windowApi.lhgdialog.tips(data.info);
				}
			});
		},function(){return;});
	});
	//取消订单
	$('.order_over').live('click',function(){
		var id  = $(this).attr('id');
		var msg = "确认将该订单完成吗？";
		windowApi.lhgdialog.confirm(msg, function(){
			$.get("{:U('Order/order_over')}",{ id: id },function(data){
				if(data.status==1){
					windowApi.lhgdialog.tips('订单完成成功！');
					$('.et_tfoot .page_refresh').click(); //刷新加载
					setInterval(setBlue,1000);
				}else{
					windowApi.lhgdialog.tips(data.info);
				}
			});
		},function(){return;});
	});
});

	var listConfig = {
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index',
			where : '',
			getWhere : function(){
				return getwheres();
			},
			showPageNav: false,
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			showPageNav: true,         //是否显示分页
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"printOrder": {
							name: "查看订单", 
							icon: "paste",
							callback: function(key, options) {
								var href = "{:U('Order/printOrder')}&id="+$(this).attr('rowid');
								var width = '1100px';
								var height = '530px';
 								var title = '查看订单';
								openDialog('Order_printOrder',href,width,height,title);
							}
						},
						"edit": {
							name: "修改订单", 
							icon: "edit",
							callback: function(key, options) {
								var status = $(this).children('td').children("input[name='status']").val();
								
								//订单完毕或者投诉完毕之后，不能修改订单
								if(status==14){
									windowApi.lhgdialog.alert('订单已完成，不能修改');return;
								}
								if(status==13){
									windowApi.lhgdialog.alert('订单投诉已处理，不能修改');return;
								}else{
									var href = "{:U('Order/edit')}&id="+$(this).attr('rowid');
									var width = '1100px';
									var height = '530px';
									var title = '修改订单';
									openDialog('Order_edit',href,width,height,title);
								}
							}
						},
						/*"confirm": {
							name: "确认订单", 
							icon: "paste",
							callback: function(key, options) {
								var val = $(this).attr('rowid');
								$.get("{:U('Order/confirm')}",{ val: val },function(data){
									windowApi.lhgdialog.tips('订单确认成功！');
									$('.et_tfoot .page_refresh').click(); //刷新加载
									setInterval(setRed,1000);
								});
							}
						},
						"cancel": {
							name: "取消订单", 
							icon: "cancel",
							callback: function(key, options) {
								var val = $(this).attr('rowid');
								var msg = "确认将该订单取消吗？";
								windowApi.lhgdialog.confirm(msg, function(){
									$.get("{:U('Order/cancel')}",{ val: val },function(data){
										if(data.status==1){
											windowApi.lhgdialog.tips('订单取消成功！');
											$('.et_tfoot .page_refresh').click(); //刷新加载
											setInterval(setBlue,1000);
										}else{
											windowApi.lhgdialog.tips(data.info);
										}
									});
								},function(){return;});
							}
						},
						"deal": {
							name: "分配订单", 
							icon: "copy",
							callback: function(key, options) {
								var orderno = $(this).attr('orderno');
								//var href    = "{:U('Order/deal')}&val="+$(this).attr('rowid');
								var href    = "{:U('Order/deal')}&id="+$(this).attr('rowid')+"&orderno="+orderno;
								var width   = '320px';
								var height  = '160px';
								var title   = '分配订单';
								openDialog('Order_deal',href,width,height,title);
							}
						},*/
						"orderbak": {
							name: "订单备注", 
							icon: "cut",
							callback: function(key, options) {
								var status = $(this).children('td').children("input[name='status']").val();
								if(status==14){
									windowApi.lhgdialog.alert('订单已完成，不能备注');return;
								}
								if(status==13){
									windowApi.lhgdialog.alert('订单投诉已处理，不能备注');return;
								}else{
									var href   = "{:U('Order/orderbak')}&id="+$(this).attr('rowid');
									var width  = '520px';
									var height = '260px';
									var title  = '订单备注';
									openDialog('Order_orderbak',href,width,height,title);
								}
							}
						},
						"delete": {
							name: "删除订单", 
							icon: "delete",
							callback: function(key, options) {
								var val = $(this).attr('rowid');
								var msg = "确认将该订单删除吗？";
								windowApi.lhgdialog.confirm(msg, function(){
									$.get("{:U('Order/del')}",{ val: val },function(data){
										if(data.status==1){
											windowApi.lhgdialog.tips('数据删除成功！');
											$('.et_tfoot .page_refresh').click(); //刷新加载
											setInterval(setRed,1000);
										}else{
											windowApi.lhgdialog.tips(data.info);
											setInterval(setRed,1000);
										}
									});
								},function(){return;});
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '订单编号',
					name : 'orderno',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '城市',
					name : 'city',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'50px',
				},
				{
					display : '状态',
					name : 'status',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'130px',
				},
				{
					display : '配送员',
					name : 'dealid',
					sortable : true,
					myclass : 'center',
					width   : '60px',	
					edit : false
				},
				{
					display : '订购者',
					name : 'username',
					sortable : true,
					myclass : 'center',
					width   : '120px',
					edit : false
				},
				/*{
					display : '联系电话',
					name : 'mobile',
					sortable : true,
					myclass : 'center',
					width   : '100px',
					edit : false
				},
				{
					display : '菜品金额',
					name : 'dishesfee',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				{
					display : '服务费',
					name : 'shipfee',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'70px',
				},
				{
					display : '优惠金额',
					name : 'cardfee',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				*/
				{
					display : '总金额',
					name : 'orderfee',
					sortable : true,
					myclass : 'center',
					width   : '60px',
					edit : false
				},
				{
					display : '服务费',
					name : 'shipfee',
					sortable : true,
					myclass : 'center',
					width:"60px",
					edit : false
				},
				{
					display : '酒水费',
					name : 'drinkfee',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				/*{
					display : '备注金额',
					name : 'b_price',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				{
					display : '是否需要打印',
					name : 'isprint',
					sortable : true,
					myclass : 'center',
					width:"95px",
					edit : false
				},*/
				{
					display : '预订单',
					name : 'isyuding',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'60px',
				},
				{
					display : '确认？',
					name : 'isconfirm',
					sortable : true,
					myclass : 'center',
					width:"50px",
					edit : false
				},
				{
					display : '下单时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '操作',
					name : 'deal',
					sortable : true,
					myclass : 'center',
					edit : false,
					width: '130px',
				}
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	
	$(function(){
		
		function setRed(){
			$('.order_1').parent('td').parent('tr').addClass('red');
		}
		function setBlue(){
			$('.order_-1').parent('td').parent('tr').addClass('blue');
		}
		
		setInterval(setRed,1000);
		setInterval(setBlue,1000);
		//setTimeout(fresh(),3000);
		//根据关键字和其他条件进行搜索
		$('.searchbtn').click(function(){
			byCondition();
		});
		
		//重置搜索条件
		$(".doreset").on("click",function(){
			clearwheres();
		});
		
		//导出订单
		$("#exportBtn").on('click',function(){
			$('#searchForm').attr('action',"{:U('Order/export')}");
			$("#searchForm").submit();
		});
		
		//导出财务报表
		$("#caiwuBtn").on('click',function(){
			$('#searchForm').attr('action',"{:U('Order/exportCaiwu')}");
			$("#searchForm").submit();
		});
		
		//动态更新餐厅
		$('#city').on('change',function(){
			var city = $(this).val();
			var type = 'outlet';
			$.get("{:U('Order/index')}",{city:city,type:type},function(data){
				$('#outletid').html(data);
			});
		});
		
		//批量删除
		$('.memberDel').on('click',function(){
			
			var val = tableList.getChecked();
			var msg = "确认要将选中的订单删除吗？";
			
			if(val){
				windowApi.lhgdialog.confirm(msg, function(){
					$.post("{:U('Order/del')}",{val:val},function(data){
						if(data.status==1){
							$('.et_tfoot .page_refresh').click(); //刷新加载
							setInterval(setRed,1000);
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				},function(){return;});
			}else{
				windowApi.lhgdialog.alert('请选择需要删除的订单！');
			}
		});
	});
	
	//获取筛选条件并组成数组
	function getwheres(){
		
		var where  = {};
		
		where.keywords= $('#keywords').val();
		where.dealid  = $('#dealid').val();
		where.status  = $('#status').val();
		where.end     = $('#end').val();
		where.start   = $('#start').val();
		where.city    = $('#city').val();
		where.outletid= $('#outletid').val();
		return where;
	}
	
	//重置搜索条件
	function clearwheres(){
		
		$('#dealid').val("");
		$('#status').val("");
		$('#keywords').val("");
		$('#start').val("");
		$('#end').val("");
		$('#city').val("");
		$('#outletid').val("");
	}
	//发送异步进行搜索
	function byCondition(){
		
		var where = tableList.config.getWhere();
		tableList.config.nowPage = 1;
		tableList.config.where   = where;
		tableList.search();
	}
	function fresh(){
		$('.page_refresh').click();
	}
	window.setInterval("fresh()",'{$refresh}'); 
</script>
</html>
